﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace SharedLIbrary
{
    public class PingableSensorList
    {
        public static ConcurrentDictionary<int, string> pingSensors = new ConcurrentDictionary<int, string>();

        public  ConcurrentDictionary<int, string> getPingSensorsQueue()
        {
            return pingSensors;
        }

        public  void setPingSensor(int sensorid, string ip)
        {
            pingSensors.AddOrUpdate(sensorid, ip, (key, oldValue) => ip);
        }

        public  List<SensorIPDataStructure> getAllFailedSensors()
        {
            KeyValuePair<int,string>[] list = pingSensors.ToArray();
            List<SensorIPDataStructure> response = new List<SensorIPDataStructure>();
            foreach(var item in list)
            {
                 response.Add(new SensorIPDataStructure(item.Key,item.Value));
            }
            return response;
        }

       
    }
}
